package com.example.musicproject_b.Controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.common.pojo.musictag;
import com.example.common.utils.Resultb;
import com.example.service.MusicTagservice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/B_admin/tag")
public class BAdminTagController {


    @Autowired
    private MusicTagservice musicTagservice;

    /**
     * @return
     * @param @param null
     * @author znk
     * @date 2024/9/26 15:00
     * 文章标签列表（包含逻辑删除）
     */
    @RequestMapping("/noalllist")
    public Resultb noalllist(int pageNum, int pageSize, String name){
        try{
            Page<musictag> page=musicTagservice.selectPageTagandByName(pageNum, pageSize, name);
            return Resultb.success(page);
        }catch (Exception e){
            return Resultb.error();
        }
    }


    /**
     * @return
     * @param @param null
     * @author znk
     * @date 2024/9/26 15:00
     * 文章标签列表（不包含逻辑删除）
     */
    @RequestMapping("/alllist")
    public Resultb alllist(int pageNum, int pageSize, String name){
        try{
            Page<musictag> page=musicTagservice.selectPageNodelectTagandByName(pageNum, pageSize, name);
            return Resultb.success(page);
        }catch (Exception e){
            return Resultb.error();
        }
    }


    /**
     * @return
     * @param @param null
     * @author znk
     * @date 2024/9/26 15:00
     * 禁用和启用标签
     */
    @RequestMapping("/startandstop")
    public Resultb startandstop(Long id){
        try{
            boolean startandstop = musicTagservice.startandstop(id);
            if (!startandstop){
                return Resultb.error("操作失败");
            }
            return Resultb.success();
        }catch (Exception e){
            return Resultb.error();
        }
    }


    /**
     * @return
     * @param @param null
     * @author znk
     * @date 2024/9/26 15:00
     * 彻底删除
     */
    @RequestMapping("/delete")
    public Resultb delete(Long id){
        try{
            boolean delete = musicTagservice.removeAllById(id);
            if (!delete){
                return Resultb.error("操作失败");
            }
            return Resultb.success();
        }catch (Exception e){
            return Resultb.error();
        }
    }

    /**
     * @return
     * @param @param null
     * @author znk
     * @date 2024/9/26 15:00
     * 修改标签
     */
    @RequestMapping("/update")
    public Resultb update(@RequestBody musictag musictag){
        try{
            boolean update = musicTagservice.updateById(musictag);
            if (!update){
                return Resultb.error("操作失败");
            }
            return Resultb.success();
        }catch (Exception e){
            return Resultb.error();
        }
    }


    /**
     * @return
     * @param @param null
     * @author znk
     * @date 2024/9/26 15:00
     * 新增标签
     */
    @RequestMapping("/add")
    public Resultb add(@RequestBody musictag musictag){
        try{
            boolean save = musicTagservice.save(musictag);
            if (!save){
                return Resultb.error("操作失败");
            }
            return Resultb.success();
        }catch (Exception e){
            return Resultb.error();
        }
    }

    /**
     * @return
     * @param @param null
     * @author znk
     * @date 2024/9/30 16:22
     * 为指定文章添加标签
     */
    @RequestMapping("/addTagToArticle")
    public Resultb addTagToArticle(Long articleId, Long tagId){
        try{
            boolean b = musicTagservice.addTagToArticle(articleId, tagId);
            if (!b){
                return Resultb.error("操作失败");
            }
            return Resultb.success();
        }catch (Exception e){
            return Resultb.error();
        }
    }


}
